import * as THREE from "three";
import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry.js"
import LightWall from "../class/LightWall";
import axios from "axios";
export const OneExp = {
	data(){
		return{
			
		}
	},
	methods:{
		// 第一次扩张
		async oneExp() {
			this.loading = true ;
			this.$parent.btnIsDis = true;
			let mapData = JSON.parse(localStorage.getItem("coldWarMap"))
			var worldMap =  this.scene.getObjectByName("worldMap")
			this.scene.remove(worldMap);
			this.map = new THREE.Object3D()
			this.MapData = mapData
			this.initMap()

			// 更换画框贴图
			var picArr = [
				{imgUrl:"img/relatedPhoto/first/Turkey3.jpg",imgDesc:"1965年11月在土耳其演习东方快车，来自不同成员国的3500名士兵参与其中。"},
				{imgUrl:"img/relatedPhoto/first/Turkey2.jpg",imgDesc:"在 1960 年代初期，北约被安卡拉授权在伊兹密尔附近短期部署中程木星导弹。北约管道系统在冷战期间建立，在危机时期提供燃料供应，也贯穿全国，政府授权北约部队使用其部分军事基地。土耳其参加了北约防空地面环境（NADGE）计划，该计划为联盟提供了强大的屏障，防止快速飞行甚至超音速的敌机侵入北约欧洲领空"},
				{imgUrl:"img/relatedPhoto/first/Grecce2.jpg",imgDesc:"东道主国(希腊)尽一切努力使北约外交部长和国防部长的会议成为一个难忘的时刻，如在雅典卫城上空组织的壮观飞越所示。"}
			]
			this.changePicTexture(picArr);
			this.initNatoMap();
			this.updateView()
			this.removeOldModel() ;
			await this.loadCountryNumber(1)
			let newCameraPos, newTargetPos,time;
			
			var Group = new THREE.Group();
			Group.name = "Jb";

			var fontAnimation,flagAnimation,arrowAnimation;
			
			var resource = new THREE.Group();
			this.scene.add(Group)
			// 加载资源
			let TurkeyLabel 	   = this.get3dLabel("土耳其",false,"20px") ;
			var flagTurkeyModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagTurkeyTexture = this.changeTexture("img/flag/Turkey.png") ;
			flagTurkeyModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Turkey";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagTurkeyTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(TurkeyLabel)
				resource.add(flag)
			})
			
			let GracceLabel 	   = this.get3dLabel("希腊",false,"20px") ;
			var flagGracceModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagGracceTexture = this.changeTexture("img/flag/Greece.png") ;
			await flagGracceModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Greece";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagGracceTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(GracceLabel)
				resource.add(flag)
			})
			
			let SovietUnionLabel 	   = this.get3dLabel("苏维埃联邦社会主义共和国",false,"20px") ;
			var flagSovietUnionModel = this.gltfLoadModel("model/public/flaggltf/scene.gltf");
			var flagSovietUnionTexture = this.changeTexture("img/flag/Soviet Union.png") ;
			await flagSovietUnionModel.then((res)=>{
				let flag = res.scene.clone();
				flagAnimation = res.animations[0];
				flag.name = "Soviet Union";
				flag.scale.set(4, 4, 4)
				flag.children[0].children[1].material.map = flagSovietUnionTexture;
				flag.children[0].children[1].material.map.needsUpdate = true;
				flag.add(SovietUnionLabel)
				resource.add(flag)
			})
			
			var wtoCreateDate = this.gltfLoadModel("model/date/1-19520218/scene.gltf")
			await wtoCreateDate.then((res) => {
				let model = res.scene.clone();
				model.scale.set(10,10,10) ;
				model.name = "19520218" ;
				fontAnimation = res.animations[0] ;
				resource.add(model)
			})
			
			let arrowLabel 	   = this.get3dLabel("黑海封锁口",true,"10px") ;
			var rightArrow = this.gltfLoadModel("model/public/rightarrow/scene.gltf");
			await rightArrow.then((res) => {
				res.scene.scale.set(7, 7, 7);
				arrowAnimation = res.animations[0]
				let rightTop = res.scene.clone();
					rightTop.name = "Arrow"
					rightTop.add(arrowLabel)
					resource.add(rightTop)
			})
			this.loading = false ;
			/////////////////////////脚本////////////////////////////////////////////
			this.firstPromptText();
			this.$refs.Lines.src = "music/lines/oneexp/1-1.mp3" ;
			this.$refs.Lines.play();
			newCameraPos = {
				x: 36.34569981033418,
				y: 122.07879729967192,
				z: 144.46826203832626
			}
			newTargetPos = {
				x: 45.45431668571693,
				y: 2,
				z: -10.6109501267050197
			}
			time = 3000
			this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, time)
			
			// 日期模型
			setTimeout(()=>{
				let model = resource.getObjectByName("19520218");
				model.position.set(45.45431668571693,20,-10)
				Group.add(model)
				this.onceActionPlay(fontAnimation,model)
			},500)
			
			// 土耳其国旗
			setTimeout(()=>{
				let flag = resource.getObjectByName("Turkey");
				flag.position.set(50.45431668571693,9,-4);
				this.onceActionPlay(flagAnimation,flag)
				Group.add(flag)
			},3000)
			
			setTimeout(()=>{
				let flag = resource.getObjectByName("Greece");
				flag.position.set(34.45431668571693,9,-4);
				this.onceActionPlay(flagAnimation,flag)
				Group.add(flag)
			},4000)
			
			// 苏维埃出现
			setTimeout(()=>{
				let flag = resource.getObjectByName("Soviet Union");
				flag.position.set(100,9,-30);
				this.onceActionPlay(flagAnimation,flag)
				Group.add(flag)
				
				this.map.children.forEach((item) => {
					if (item.properties.name == "Soviet Union") {
						item.children.forEach((area) => {
							if (area.type == "Mesh") {
								area.material.color.set('#a90209')
							}
						})
					}
				})
			},7000)
			
			
			// 箭头出现
			setTimeout(()=>{
				let Arrow = resource.getObjectByName("Arrow");
				Group.add(Arrow)
				Arrow.rotateY(Math.PI/1.5)
				Arrow.position.set(25.45431668571693,5,10);
				this.onceActionPlay(arrowAnimation,Arrow)
				
				setTimeout(()=>{
					let newCameraPos = {
						x: 13.835609323056534,
						y: 40.61336405430142,
						z: 68.51784010242665
					}
					let newTargetPos = {
						x: 50.45431668571693,
						y: 9,
						z: -4
					}
					
					this.animateCamera(this.camera.position, this.controls.target, newCameraPos, newTargetPos, 3000)
					// this.showPointer3dLabel();
				},1000)
			},14000)
			this.scene.add(Group)
		},
	}
}